<html>
<head><meta charset="utf-8"><title>print_def_path · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/print_def_path.html">print_def_path</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="216933024"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/print_def_path/near/216933024" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/print_def_path.html#216933024">(Nov 16 2020 at 21:13)</a>:</h4>
<p>Hmm <span class="user-mention" data-user-id="119009">@eddyb</span> do you have any idea what <a href="https://github.com/rust-lang/rust/blob/f5230fbf76bafd86ee4376a0e26e551df8d17fec/compiler/rustc_middle/src/ty/print/mod.rs#L120-L123">this logic</a> is trying to do?</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="w">                </span><span class="k">if</span><span class="w"> </span><span class="n">substs</span><span class="p">.</span><span class="n">len</span><span class="p">()</span><span class="w"> </span><span class="o">&gt;=</span><span class="w"> </span><span class="n">generics</span><span class="p">.</span><span class="n">count</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
</code></pre></div>
<p>seems...suspicious (did I write that?!?!)</p>



<a name="216933215"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/print_def_path/near/216933215" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/print_def_path.html#216933215">(Nov 16 2020 at 21:15)</a>:</h4>
<p>I think I just marked a couple months of mentions as "read", thanks Zulip,,,</p>



<a name="216933448"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/print_def_path/near/216933448" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/print_def_path.html#216933448">(Nov 16 2020 at 21:16)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> I think I did and it decides whether to apply substs (when you're in a generics-child of the impl, like an assoc item) or not (e.g. nested defs that have the impl in their def path ancestors)</p>



<a name="216933525"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/print_def_path/near/216933525" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/print_def_path.html#216933525">(Nov 16 2020 at 21:17)</a>:</h4>
<p>hmm</p>



<a name="216933530"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/print_def_path/near/216933530" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/print_def_path.html#216933530">(Nov 16 2020 at 21:17)</a>:</h4>
<p>because we don't have generic modules, I believe the substs are always empty when that condition is false</p>



<a name="216933539"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/print_def_path/near/216933539" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/print_def_path.html#216933539">(Nov 16 2020 at 21:17)</a>:</h4>
<p>i.e. there is an implicit <code>Option</code> around the substs</p>



<a name="216933626"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/print_def_path/near/216933626" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/print_def_path.html#216933626">(Nov 16 2020 at 21:18)</a>:</h4>
<p>I don't really understand , but ok</p>



<a name="216933676"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/print_def_path/near/216933676" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/print_def_path.html#216933676">(Nov 16 2020 at 21:19)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">impl</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">Bar</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">foo</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="k">struct</span> <span class="nc">X</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="216933700"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/print_def_path/near/216933700" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/print_def_path.html#216933700">(Nov 16 2020 at 21:19)</a>:</h4>
<p>you get <code>{impl#0}::foo</code> and <code>{impl#0}::foo::X</code> paths from that</p>



<a name="216933736"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/print_def_path/near/216933736" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/print_def_path.html#216933736">(Nov 16 2020 at 21:19)</a>:</h4>
<p>the former may have substs (when provided at all) but the latter can't</p>



<a name="216933840"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/print_def_path/near/216933840" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/print_def_path.html#216933840">(Nov 16 2020 at 21:20)</a>:</h4>
<p>the conditional allows getting e.g. <code>&lt;Bar&lt;String&gt; as Foo&gt;::foo</code> when <code>substs = [String]</code> for the former, while not breaking when substs aren't available</p>



<a name="216933858"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/print_def_path/near/216933858" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/print_def_path.html#216933858">(Nov 16 2020 at 21:20)</a>:</h4>
<p>the condition could just be <code>if !substs.is_empty()</code></p>



<a name="216933934"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/print_def_path/near/216933934" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/print_def_path.html#216933934">(Nov 16 2020 at 21:21)</a>:</h4>
<p>ok</p>



<a name="216933949"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/print_def_path/near/216933949" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/print_def_path.html#216933949">(Nov 16 2020 at 21:21)</a>:</h4>
<p>that helps for my purposes, thanks</p>



<a name="216934156"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/print_def_path/near/216934156" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/print_def_path.html#216934156">(Nov 16 2020 at 21:22)</a>:</h4>
<p>just remembered to make <code>X</code> a type (instead of just a <code>static</code>), because this means you can <code>rustc</code> to actually print the path quite easily (<code>let () = X;</code> inside <code>fn foo</code>)</p>



<a name="216934227"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/print_def_path/near/216934227" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/print_def_path.html#216934227">(Nov 16 2020 at 21:23)</a>:</h4>
<p>if I'm not mistaken it will show up as <code>&lt;Bar&lt;T&gt; as Foo&gt;::foo::X</code></p>



<a name="216934294"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/print_def_path/near/216934294" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/print_def_path.html#216934294">(Nov 16 2020 at 21:23)</a>:</h4>
<p>(the fun variant of this is nesting things in closures, because there the type printing of a closure vs the path printing is quite different)</p>



<a name="216934369"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/print_def_path/near/216934369" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/print_def_path.html#216934369">(Nov 16 2020 at 21:24)</a>:</h4>
<p>shouldn't it be <code>&lt;Bar&lt;T&gt; as Foo&gt;</code>? <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span></p>



<a name="216934655"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/print_def_path/near/216934655" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/print_def_path.html#216934655">(Nov 16 2020 at 21:26)</a>:</h4>
<p><span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span> <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span> <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span> fixed</p>



<a name="216935630"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/print_def_path/near/216935630" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/print_def_path.html#216935630">(Nov 16 2020 at 21:34)</a>:</h4>
<p><span class="user-mention silent" data-user-id="119009">eddyb</span> <a href="#narrow/stream/131828-t-compiler/topic/print_def_path/near/216934294">said</a>:</p>
<blockquote>
<p>(the fun variant of this is nesting things in closures, because there the type printing of a closure vs the path printing is quite different)</p>
</blockquote>
<p>I thought we updated them to be somewhat similar <a href="https://github.com/rust-lang/rust/pull/77069/files#diff-0485903fe0105680719870f73d0211551183b03f6d54b05d1667992cf0ca776b">https://github.com/rust-lang/rust/pull/77069/files#diff-0485903fe0105680719870f73d0211551183b03f6d54b05d1667992cf0ca776b</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>